import Vue from 'vue'
import VueRouter from 'vue-router'
import shouye from '../views/shouye.vue'
import allshop from '../views/allshop.vue'
import fuli from '../views/fuli.vue'
import dingdan from '../views/dingdan.vue'
import people from '../views/people.vue'
import detali from '../views/detali.vue'
import carts from '../components/people/Cart.vue'
import Affirm from '../views/Affirm.vue'
Vue.use(VueRouter)

const routes = [
    // component: HomeView
			{
				path:'/',
				redirect:'shouye',
			},
			{
				path:'/allshop',
				name:'allshop',
				component:allshop,
			},
			{
				path:'/dingdan',
				name:'dingdan',
				component:dingdan,
			},
			{
				path:'/shouye',
				name:'shouye',
				component:shouye,
			},
			{
				path:'/fuli',
				name:'fuli',
				component:fuli,
			},
			{
				path:'/detali',
				name:'detali',
				component:detali,
			},
			{
				path:'/Affirm',
				name:'Affirm',
				component:Affirm,
			},
			{
				path:'/people',
				name:'people',
				component:people,
				children:[
					{
						path:'/',
						name:'carts',
						redirect:'carts',
					},
					{
						path:'carts',
						name:'carts',
						component:carts
					}
				]
			}
			
		]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//获取push方法对象
const originPush=VueRouter.prototype.push
//重写铺设方法
VueRouter.prototype.push=function(location){
	return originPush.call(this,location).catch(err=>{})
}

//根据需求，进入个人中心页面，用户需要先登录，否则提示用户登录
//路由拦截：（前置导航守卫，后置导航守卫

//全局导航守卫
// router.beforeEach((to,from,next)=>{
// 	if(to.path=='/user'){
// 		let mytoken=localStorage.getItem('x-auth-token')
// 		if(mytoken){//如果登录
// 			next()//放行
// 		}else{
// 			alert('请先登录')
// 		}
// 		return
// 	}
// 	next()
// })

export default router
